package 力扣日常刷题.木22二月.第17天223;

import java.util.PriorityQueue;

/**
 * @author 帅小伙
 * @date 2022/2/23
 * @description
 */
public class Demo149最小的k个数 {


    public int[] getLeastNumbers(int[] arr, int k) {
        int[] ans = new int[k];
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(k);

        for (int i : arr) priorityQueue.add(i);

        for (int i = 0; i < k; i++) ans[i] = priorityQueue.poll();
        return ans;
    }
}
